<template>
	<view class="">
		<view class="m-2 p-3 bg-white rounded-20 d-flex j-sb">
			<view class="">规格项目名称</view>
			<view class="">
				<input type="text" class="text-right" v-model="spec_name" @input="spec_input" value="" placeholder="请输入规格项目名称" />
			</view>
		</view>
		<u-toast ref="uToast" />
		<view class="footer">
		</view>
		<view class="bg-white release  py-2 w-100 position-fixed bottom-0">
			<button type="warn" :disabled="isDisable" @click="next_sub">保存</button>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				spec_name:"",
				specification_id:0,// 规格ID
			}
		},
		methods:{
			// 规格名称
			spec_input(e){
				this.spec_name=e.detail.value
			},
			// 保存
			next_sub(){
				if(this.specification_id){
					this.$H.post("v2/store/goods/specification/update",{
						specification_id:this.specification_id,
						specification_name:this.spec_name
					}).then(res=>{
						console.log('res')
						this.$refs.uToast.show({
							title: '修改成功',
							type: 'success',
							back:true
						})
					})
				}else{
					this.$H.post("v2/store/goods/specification/add",{
						name:this.spec_name
					}).then(res=>{
						 console.log(res)
						this.$refs.uToast.show({
						 	title: '添加成功',
						 	type: 'success',
							back: true
						})
					})
				}
			}
		},
		onLoad(e) {
			if(e.specification_id){
				this.specification_id=e.specification_id
				this.$H.post("v2/store/goods/specification/detail",{
					specification_id:this.specification_id
				}).then(res=>{
					this.spec_name=res.data.specification_name
					console.log(res)
				})
			}
		}
	}
</script>

<style>
</style>
